package projorientado;

import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
import projorientado.anpr.PlateRecognizerVisitor;
import projorientado.image.ImageLayerData;

public class DebugVisitorAnpr implements PlateRecognizerVisitor {

    private int imgCount = 0;
    private String dir;
    
    public DebugVisitorAnpr(String dir) {
        this.dir = dir;
    }

    public void log(String str) {
        System.out.println(str);
    }
    
    public void visitImage(ImageLayerData image, String info, int visitCode) {
        visitImage(image.toBWImage(),info,visitCode);
    }

    public void visitValue(double value, String info, int visitCode) {
        log("[" + visitCode + "]=" + info + " (Valor="  + value + ")");
    }

    public void visitLog(String info, int visitCode) {
        log("[" + visitCode + "]=" + info);
    }

    public void visitObject(Object obj, String info, int visitCode) {
        log("[" + visitCode + "]=" + info + " (Objeto="  + obj + ")");
    }

    public void visitImage(BufferedImage image, String info, int visitCode) {
        try {
            File f = new File(dir + imgCount + ".jpg");
            ImageIO.write(image, "jpg", f);
            log("[" + visitCode + "]=" + info + " (Salvo com numero " + imgCount++ + ")");
        } catch(Exception e) {
            
        }
    }
    
}
